home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-wwdwch.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  68 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                     S Y S T E M . W W D _ W C H A R                      --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.2 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. package body System.WWd_WChar is
  27.  
  28.    -------------------------------
  29.    -- Wide_Width_Wide_Character --
  30.    -------------------------------
  31.  
  32.    function Wide_Width_Wide_Character
  33.      (Lo, Hi : Wide_Character)
  34.       return   Natural
  35.    is
  36.       W : Natural;
  37.       P : Natural;
  38.  
  39.    begin
  40.       W := 0;
  41.  
  42.       for C in Lo .. Hi loop
  43.          P := Wide_Character'Pos (C);
  44.  
  45.          --  If we are in wide character range, the length is always 3
  46.          --  and we are done, since all remaining characters are the same.
  47.  
  48.          if P > 255 then
  49.             return Natural'Max (W, 3);
  50.  
  51.          --  If we are in character range then use length of character image
  52.          --  Is this right, what about wide char encodings of 80-FF???
  53.  
  54.          else
  55.             declare
  56.                S : Wide_String := Character'Wide_Image (Character'Val (P));
  57.  
  58.             begin
  59.                W := Natural'Max (W, S'Length);
  60.             end;
  61.          end if;
  62.       end loop;
  63.  
  64.       return W;
  65.    end Wide_Width_Wide_Character;
  66.  
  67. end System.WWd_WChar;
  68.